

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/queue.h>
#include <unistd.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <signal.h>
#include <string>
#include <iostream>
#include   <arpa/inet.h>  
 #include <netdb.h>

using namespace std;

int   main(int argc, char *argv[])  
{ 
	if(argc < 3)
	{
		cout<<argv[0]<<" host port"<<endl;
		return 0;
	}
        int maxnum = 2;
        if(argc >= 4)
            maxnum = atoi(argv[3]); 
	int sock;  
	struct sockaddr_in   sin;  
	sock  =  socket(AF_INET, SOCK_STREAM, 0);  
	if(sock  ==   -1)  
	{  
		perror("client   socket");  
		return   -1;  
	}  
	memset(&sin,   0,   sizeof(sin));  
	struct hostent *hp;
	hp = gethostbyname(argv[1]);
	sin.sin_family   =   AF_INET;  
        bcopy(hp->h_addr, &(sin.sin_addr.s_addr), hp->h_length);
	sin.sin_port   =   htons( atoi(argv[2]));   
	if(connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)  
	{  
		perror("client   connect");  
		return   -1;  
	}
	char buf[1024];
	int iln= sprintf(buf,"GET /stop HTTP/1.1\r\nHost: localhost:10105\r\nUser-Agent: Mozilla/5.0 Firefox/3.0.1\r\nAccept: text/html\r\nKeep-Alive: 20\r\nConnection: Close\r\n\r\n");


	buf[iln] = '\0';

	send(sock, buf, iln, 0);
	if((iln = read(sock, buf, sizeof(buf))) > 0)
	{
		buf[iln] = '\0';  
		cout<<iln<<":"<< buf <<endl;
	}

	close(sock);
	return 0;

}
